<?php

use yii\db\Migration;

/**
 * Class m230127_093931_rbac_common_image
 */
class m230127_093931_rbac_common_image extends Migration
{
    /**
    * {@inheritdoc}
    */
    public function safeUp()
    {
        $auth = Yii::$app->authManager;
 
        $permissionCreate = $auth->createPermission('createCommonImage');
        $auth->add($permissionCreate);
 
        $permissionUpdate = $auth->createPermission('updateCommonImage');
        $auth->add($permissionUpdate);
 
        $permissionDelete = $auth->createPermission('deleteCommonImage');
        $auth->add($permissionDelete);
 
        $permissionBrowse = $auth->createPermission('browseCommonImage');
        $auth->add($permissionBrowse);
 
        $userRole = $auth->createRole('commonImageUser');
        $auth->add($userRole);
 
        $managerRole = $auth->createRole('commonImageManager');
        $auth->add($managerRole);
 
        $auth->addChild($userRole, $permissionBrowse);
 
        $auth->addChild($managerRole, $permissionCreate);
        $auth->addChild($managerRole, $permissionUpdate);
        $auth->addChild($managerRole, $permissionDelete);
        $auth->addChild($managerRole, $permissionBrowse);
    }
 
    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $auth = Yii::$app->authManager;
 
        $auth->remove($auth->getPermission('createCommonImage'));
        $auth->remove($auth->getPermission('updateCommonImage'));
        $auth->remove($auth->getPermission('deleteCommonImage'));
        $auth->remove($auth->getPermission('browseCommonImage'));
        $auth->remove($auth->getRole('commonImageUser'));
        $auth->remove($auth->getRole('commonImageManager'));
    }
}
